<template>
  <el-card>

    <div slot="header" class="card-title">
      {{ obj.objectName }}
    </div>

    <el-table
      :data="obj.resources"
      fit
    >
      <el-table-column
        label="属性"
        prop="item"
        width="140"
      >
      </el-table-column>

      <el-table-column
        label="值"
        prop="value"
      >
      </el-table-column>

      <el-table-column
        label="操作"
        prop="ops"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.ops.indexOf('R') !== -1"
            class="el-icon-view"
            size="small"
          >
            读数
          </el-button>
          <el-button
            slot="reference"
            v-if="scope.row.ops.indexOf('W') !== -1"
            type="primary"
            class="el-icon-edit"
            size="small"
          >
            修改
          </el-button>

          <el-button
            v-if="scope.row.ops.indexOf('E') !== -1"
            type="info"
            class="el-icon-setting"
            size="small"
            @click="handleExecute(scope)"
          >
            执行命令
          </el-button>
        </template>
      </el-table-column>
    </el-table>

  </el-card>
</template>

<script>
export default {
  name: 'ObjectView',

  props: {
    obj: {
      type: Object,
      required: true
    }
  },

  methods: {
    handleWrite(scope) {
      
    },
    handleExecute(scope) {
      if (scope.row.value == "running") {
        setTimeout(() => {
          scope.row.value = "stopped"
          this.$message({
            message: '关机成功',
            type: 'success'
          });
        }, 1000)
      } else if (scope.row.value == "stopped") {
        setTimeout(() => {
          scope.row.value = "running"
          this.$message({
            message: '开机成功',
            type: 'success'
          });
        }, 1000)
      }
    }
  }
}
</script>

<style lang='scss'>
.card-title {
  text-transform: capitalize;
  font-weight: bold;
}
.map-test {
  width: 100%;
  height: 50vh;
}
</style>
